package com.example.demo.service;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.example.demo.bean.Order;
import com.example.demo.dao.OrderDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class OrderService {
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private GoodsService goodsService;
    @LcnTransaction//分布式事务 加上此注解会回滚服务提供者
    public boolean add(){
        Order order=new Order();
        order.setCreateTime(System.currentTimeMillis());
        order.setGoodsId("1");
        orderDao.save(order);
        //调用商品服务 减一
        goodsService.jian();
//        int i=1/0;
        return true;
    }
}
